import React, { Component } from 'react';
import {NavLink} from "react-router-dom"
import {get_hotcity} from '../../api/index'
class Hot_d extends Component {
    constructor(){
        super()
        this.state={
            city_name:[]
        }
    }
    componentDidMount(){
        get_hotcity()
        .then(res=>{
            // console.log(res.data)
            this.setState({
                city_name:res.data
            })
        })
    }
    render() {
        let city_name
        if(this.state.city_name.length===0 || this.state.city_name==null){
            city_name=null
        }else{
            city_name=this.state.city_name.map((val)=>{
                return (
                    <li key={val.id}>
                        <NavLink to={'/city/'+val.id}>
                            {val.name}
                        </NavLink>
                    </li>
                )
            })
        }

      return (
        <div className='hot_d'>
            <h3>热门城市</h3>
           <ul className='hot_list_1'>{city_name}</ul>
        </div>
      );
    }
  }
  export default Hot_d